const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
exports.main = async (event, context) => {
  console.log(event)
  const target_db = db.collection(event.collection)
  try {
    return await target_db.aggregate().lookup({
        from: 'user_data',
        localField: 'user_openid',
        foreignField: 'openid',
        as: 'user_data',
      })
      .sort({
        score: -1,
        score_time: 1
      })
      .skip(20 * event.skip)
      .limit(event.limit)
      .end()
  } catch (e) {
    console.log(e)
  }
}